#!/usr/bin/env python
# coding: utf-8

from datetime import datetime
import txmongo
from txmongo.dbref import DBRef

from twisted.internet import defer, reactor
 
@defer.inlineCallbacks
def example():
    mongo = yield txmongo.MongoConnection()

    db = mongo.ide  #  database
    members = mongo.ide_member.members  # collection
    sections = db.sections
    nodes = db.nodes
    
    s_life = yield sections.find_one({'name':'life'})
    
    if s_life:
        node_1 = {
                     'name':'beauty',
                     'title':'爱美丽',
                     'theme':'default',
                     'order': 11,
                     'desc':'不一定是天使, 照样爱美丽',
                     'acl':['user'],
                     'topic_count':0,
                     'icon': 'default.gif',
                     'created': datetime.now(),
                     'updated': datetime.now(),
                     'section':DBRef(sections, s_life['_id'])
        }
        yield nodes.insert(node_1, True)
        print 'ok'
    
    
    


if __name__ == '__main__':
    example().addCallback(lambda ign: reactor.stop())
    reactor.run()